﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Micrhard.FMCG.Server.Interface;
using Microsoft.Practices.Unity;
using Microhard.Permission.Interface;
using Micrhard.FMCG.Server.Models;
using Microhard.Permission.MVCFilter;
using Microhard.WebUI.Models;
using Microhard.Core.DBUtility;
using Microhard.Core;
using Microhard.Permission_MembershipImpl;

namespace Microhard.FMCG.WebUI.Areas.Tools.Controllers
{
    public class FMCGToolController : Controller
    {
        [MVCFilterAtrForLogon()]
        public ActionResult GetEmpList(AttriubteOfSelectList ctrAttr)
        {
            //获得当前用户所在公司
            IEmployee resp = IoC.Resolve<IEmployee>();
            var cmp = resp.GetUserCompanyByUserName(this.GetCurrentUserName());
            var emps = resp.Query(new EmployeeModel { CompanyID = cmp.CompanyID, Range = int.Parse(ctrAttr.Parms) });
            ctrAttr.Data = emps.Select(r => new SelectData
            {
                ID = r.EmployeeID.ToString(),
                Name = r.Name
            }).ToList();
            return View("SelectList", ctrAttr);
        }

        [MVCFilterAtrForLogon()]
        public ActionResult GetKAList(AttriubteOfSelectList ctrAttr)
        {
            var userName = this.GetCurrentUserName();
            IEmployee emp = IoC.Resolve<IEmployee>();
            var cmp = emp.GetUserCompanyByUserName(userName);
            IKA ka = IoC.Resolve<IKA>();
            var comp = ka.GetKAByCompanyID(cmp.CompanyID);
            ctrAttr.Data = comp.Select(r => new SelectData
            {
                ID = r.KAID.ToString(),
                Name = r.Name
            }).ToList();
            return View("SelectList", ctrAttr);
        }
    }
}
